import java.util.HashMap;
import java.util.Map;

/**
 * @author LKQ
 * @date 2022/2/24 16:08
 * @description 自顶向下记忆化搜索 f(i) = i % 2 + 1 + f(i / 2), f(i) = i % 3 + 1 + f(i / 3) 尽量使一天吃一个橘子的操作少
 */
public class FormalSolution {
    public static void main(String[] args) {
        FormalSolution solution = new FormalSolution();
        solution.minDays(56);
    }
    Map<Integer, Integer> map = new HashMap<>();
    public int minDays(int n) {
        if(n <= 1) {
            return n;
        }
        if (map.containsKey(n)) {
            return map.get(n);
        }
        map.put(n, Math.min( n % 2 + 1 + minDays(n / 2), n % 3 + 1 + minDays(n / 3)));
        return map.get(n);
    }
}
